package com.turnengine.client.global.user.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Verify User.
 */
public class VerifyUser implements IVerifyUser {

	/** The command id. */
	public static final short COMMAND_ID = 502;

	/** The id. */
	private int id;
	/** The code. */
	private long code;
	/** The address. */
	private int address;

	/**
	 * Creates a new Verify User.
	 */
	public VerifyUser() {
	}

	/**
	 * Creates a new Verify User.
	 * @param id the id
	 * @param code the code
	 * @param address the address
	 */
	public VerifyUser(int id, long code, int address) {
		setId(id);
		setCode(code);
		setAddress(address);
	}

	/**
	 * Creates a new Verify User.
	 * @param iVerifyUser the i verify user
	 */
	public VerifyUser(IVerifyUser iVerifyUser) {
		setId(iVerifyUser.getId());
		setCode(iVerifyUser.getCode());
		setAddress(iVerifyUser.getAddress());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the code.
	 * @return the code.
	 */
	public long getCode() {
		return code;
	}

	/**
	 * Returns the address.
	 * @return the address.
	 */
	public int getAddress() {
		return address;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the code.
	 * @param code the code to set.
	 */
	public void setCode(long code) {
		this.code = code;
	}

	/**
	 * Sets the address.
	 * @param address the address to set.
	 */
	public void setAddress(int address) {
		this.address = address;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(239, 37);
		hash.append(id);
		hash.append(code);
		hash.append(address);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof VerifyUser) {
			VerifyUser compare = (VerifyUser) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.code, compare.code);
			equals.append(this.address, compare.address);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IVerifyUser compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.code, compare.getCode());
		builder.append(this.address, compare.getAddress());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		string.append("code", code);
		string.append("address", address);
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
